Skip to content

utils: fix ensure_file() to use lstat() instead of stat()#759

Closed
kishansaaai wants to merge 1 commit into
containers:mainfrom
kishansaaai:fix/733-ensure-file-use-lstat
Closed

utils: fix ensure_file() to use lstat() instead of stat()#759
kishansaaai wants to merge 1 commit into
containers:mainfrom
kishansaaai:fix/733-ensure-file-use-lstat

Conversation

@kishansaaai
Copy link
Copy Markdown

Summary

Fixes #733.

ensure_file() intends to reject symlinks as bind-mount destinations
via S_ISLNK(buf.st_mode), but uses stat() which follows symlinks,
making this check permanently dead code.

Fix: replace stat() with lstat() so the symlink check actually works.

Testing

Existing test suite passes. The S_ISLNK branch is now reachable.

stat() follows symlinks, making the S_ISLNK(buf.st_mode) check
permanently dead code. Switch to lstat() so symlinks are correctly
detected and rejected as bind-mount destinations.

Fixes containers#733

Signed-off-by: SAI KISHAN A <222060771+kishansaaai@users.noreply.github.com>
@kishansaaai kishansaaai force-pushed the fix/733-ensure-file-use-lstat branch from 718faf5 to 412b277 Compare June 6, 2026 18:34
Copy link
Copy Markdown
Contributor

@rusty-snake rusty-snake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has anything changed from #737?

Comment thread utils.c
Comment on lines 514 to 515
the kernel will accept any non-directory. If it's a symlink, follow
it and look at the target: again, any non-directory is good enough.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be updated.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @rusty-snake. I see that #737 already res this by clarifying the comments the stat() behavior was intent for the dangling symlink case, which I had missed. I'll close th Apologies for the noise.

@kishansaaai kishansaaai closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ensure_file() uses stat() instead of lstat(), making S_ISLNK check dead code

2 participants